package com.guoxin.chapter1;

/**
 * 不共享数据的Thread
 *
 * @author guoxin
 * @date 2019/8/8
 */
public class NotSharedDataThread {

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(new MyThread(), "T" + i).start();
        }
    }

    private static class MyThread implements Runnable {
        /**
         * count 不是共享变量
         */
        private int count = 5;

        @Override
        public void run() {
            while (count > 0) {
                System.out.println("由 " + Thread.currentThread().getName() + " 计算的结果为：" + count);
                count--;
            }
        }
    }
}
